package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Guide;
import com.ruoyi.system.mapper.GuideDao;
import com.ruoyi.system.service.GuideService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class GuideServiceImpl extends ServiceImpl<GuideDao, Guide> implements GuideService {
    @Override
    public boolean createGuide(Guide guide) {
        Guide g = new Guide();
        g.setAuthor(guide.getAuthor());
        g.setGuide(guide.getGuide());
        g.setDatetime(guide.getDatetime());
        g.setAuditor(guide.getAuditor());
        g.setStatus(guide.getStatus());
        return baseMapper.insert(g) > 0;
    }

    @Override
    public Guide getGuideById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public boolean updateGuide(Guide guide) {
        LambdaQueryWrapper<Guide> lqw = new LambdaQueryWrapper();
        lqw.eq(Guide::getId, guide.getId());
        Guide g = baseMapper.selectOne(lqw);
        if (g == null){
            throw new RuntimeException("Guide not found");
        }
        g.setAuthor(guide.getAuthor());
        g.setGuide(guide.getGuide());
        g.setDatetime(guide.getDatetime());
        g.setAuditor(guide.getAuditor());
        g.setStatus(guide.getStatus());
        return baseMapper.updateById(g) > 0;
    }

    @Override
    public boolean deleteGuide(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
